<?php

namespace App\Library;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class HttpClient
{
    /**
     * 获取token
     * @return string
     */
    public function getToken()
    {
        $token = strtoupper(md5(time()));
        return md5($token);
    }

    /**
     * 请求post数据
     * @param $params
     * @param $header
     * @return void
     */
    public function post($params,$header = [])
    {
        $result = $params;
        unset($result['action']);
        $api = config('links.' . env('APP_ENV')) . 'v1/';

        Log::info("请求地址===" . $api . $params['action']);

        $response = Http::withHeaders([
            'Content-Type' => 'application/json',
            'Authorization' => "Bearer " . $this->getToken()
        ])->retry(3, 100)->post($api . $params['action'], $params);
    }
}
